import subprocess
from time import sleep

from appium import webdriver
from appium.options.common.base import AppiumOptions
from appium.webdriver.common.appiumby import AppiumBy

from basic.basedriver import DRIVER

# el1 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text(\"小米上新\")")
# el1.click()
# el2 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().className(\"android.view.ViewGroup\").instance(29)")
# el2.click()
# el3 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().className(\"android.widget.ImageView\").instance(6)")
# el3.click()
# el4 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text(\"去购买\").instance(2)")
# el4.click()
# el5 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().resourceId(\"com.xiaomi.shop.plugin.rank:id/detail_product_buy_tv\").instance(0)")
# el5.click()
# el6 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text(\"加入购物车\")")
# el6.click()
# el7 = driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text(\"加入购物车\")")
# el7.click()
# el8 = driver.find_element(by=AppiumBy.XPATH, value="//android.widget.TextView[@text=\"购物车\"]")
# el8.click()
#
# driver.quit()

from basic.basepage import BasePage



class PageShoppingNew(BasePage):
    def buy_to_new_product(self):
        self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().className(\"android.view.ViewGroup\").instance(28)").click()
        sleep(10)
        self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().className(\"android.widget.ImageView\").instance(6)").click()
        sleep(3)
        self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().text(\"去购买\").instance(2)").click()
        sleep(3)
        self.driver.find_element(by=AppiumBy.ANDROID_UIAUTOMATOR, value="new UiSelector().resourceId(\"com.xiaomi.shop.plugin.rank:id/detail_product_buy_tv\").instance(0)").click()
        return self


    def goto_shopping_cart(self):
        from page.page_shopping.page_function_shopping_cart import PageShoppingCart
        return PageShoppingCart()




if __name__ == '__main__':
    from page.page_main import PageMain
    obj = PageMain()
    obj.goto_xiaomi_new_product().buy_to_new_product().goto_shopping_cart()

